<template>
  <div style="height: 50px;">
        <el-button @click="">新增</el-button>
        <el-button @click="Show()">查询</el-button>
        <el-button @click="upd()">修改</el-button>
        <el-button @click="del()">删除</el-button>
       <!--  <el-button @click="Export()">导出</el-button> -->
    </div>
<el-form :inline="true" :model="page" class="demo-form-inline">
        <el-form-item label="废料编号">
            <el-input v-model="page.ProductionWasteNumber" placeholder="废料编号" clearable />
        </el-form-item>
        <el-form-item label="废料主题">
            <el-input v-model="page.ProductionWasteTopic" placeholder="废料编号" clearable />
        </el-form-item>
        <el-form-item label="废料日期">
            <el-date-picker
        v-model="page.SProductionDate"
        type="date"
        placeholder="Pick a Date"
        format="YYYY/MM/DD"
        value-format="YYYY-MM-DD"
      />- 
      <el-date-picker
        v-model="page.EProductionDate"
        type="date"
        placeholder="Pick a Date"
        format="YYYY/MM/DD"
        value-format="YYYY-MM-DD"
      />



        </el-form-item>
        <el-form-item label="添加人">
            <el-input v-model="page.AddName" placeholder="添加人" clearable />
        </el-form-item>
        </el-form>


 <el-table :data="tableData" stripe style="width: 100%" @selection-change="handleSelectionChanges">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="productionWasteNumber" label="生产废料编号" width="280px" />
        <el-table-column prop="productionWasteTopic" label="生产废料主题" width="280px" />
        <el-table-column prop="pDocumentMakers" label="制单人员" width="280px" />
        <el-table-column prop="productionDate" label="废料日期" width="280px" >
            <template #default="scope">
                {{ (scope.row.productionDate).substring(0, 10)}}
            </template>
        </el-table-column>
        <el-table-column prop="pScrapsNumber" label="废料数量" width="280px" />
        <el-table-column prop="pIsStorage" label="入库状态" width="280px">
            <template #default="scope">
                {{ scope.row.pIsStorage == 2 ? "无需入库" : "未申请入库" }}
            </template>
        </el-table-column>
        <el-table-column  label="操作" width="280px" >
            <template #default="scope">
                <el-button v-show="scope.row.pIsStorage == 1" @click="RuKu(scope.row.pwId)">申请入库</el-button>
             </template>
        </el-table-column>
        </el-table>
</template>

<script setup lang='ts'>
import axios from 'axios'
import { ElMessage, ElMessageBox } from 'element-plus';
import { ref, reactive, onMounted, computed } from 'vue'
import * as XLSX from 'xlsx';
import { useRouter } from 'vue-router';
const router = useRouter();
import http from '../../../http.js'


const page=reactive({
    pageIndex:1,
    pageSize:10,
    totalCount:0,
    pageCount:0,
    ProductionWasteNumber:'',
    ProductionWasteTopic:'',
    SProductionDate:'',
    EProductionDate:'',
    AddName:''
    
})


onMounted(() => {
    Show()
})

//选中列表的复选框
const check = ref([])
const handleSelectionChanges = (val: User[]) => {
    check.value = val
    console.log(check.value)
}
const tableData = ref([])
const Show=()=>{
    axios.get(http.zblnb + '/sc/api/Scraps/GetScrapsProduct',{
        params:{
            Pindex:page.pageIndex,
            Psize:page.pageSize,
            ProductionWasteNumber:page.ProductionWasteNumber||'',
            ProductionWasteTopic:page.ProductionWasteTopic||'',
            ProductionDate:page.SProductionDate||'',
            EProductionDate:page.EProductionDate||'',
            AddName:page.AddName||''
        }
    }).then((res)=>{
        console.log(res.data.data);
        tableData.value=res.data.data.list
        }
    )
}


//删除条件
const DELinfo = ref({
    "pspId": [],
    "delName": "1",
     delTime:"2024-06-09",
    "office_Id": "1",
    "user_Id": 1,
})

//删除
const del = () => {
    ElMessageBox.confirm(
        '确认删除吗?',
        '警告',
        {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'error',
        }
    )
        .then(() => {
            let ids = check.value.map(ele => ele.pwId);
            DELinfo.value.pspId = ids;
            console.log(DELinfo.value);
            axios.post(http.zblnb + '/sc/api/Scraps/DelScrapsProduct', DELinfo.value)
                .then(res => {
                    console.log(res.data.data);
                    if (res.data.data > 0) {
                        ElMessage.success('删除成功')
                        Show();
                    }
                    else {
                        ElMessage.error('删除失败');
                    }
                })
                .catch(err => {
                    console.log(err);
                })
        })
        .catch(() => {

        })
}
//跳转修改页面
const upd = () => {
    let strippingId = check.value.map(ele => ele.pwId);
    router.push('/UpdScraps?id='+strippingId);
}


const RuKu=(id:number)=>{
    router.push('/AddWarehouseSApp?idas='+id);
}

</script>

<style></style>